package filecheck;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileNameCheck {

	/**
	 * @param args
	 */
	private String FileName ;
	private int number;
	private File path;
	public FileNameCheck(){
		FileName = null;
		number = 0;
		path = null;
	}
	private void getFilePath(String File){
		FileName = File;
		if(FileName != null&&FileName.length()>0){
			path = new File(FileName);
			}
	}
	public void FileHandle(String File){
		getFilePath(File);
		if(path == null){
			System.out.println("please init the file name first");
		}
		FileInputStream fis = null;		
		try{
			byte []b = new byte[1000];
			StringBuffer sb = new StringBuffer();
			fis = new FileInputStream(path);
			int length = 0;
			length = fis.available();
			while(length>0){
				if(length>1000){
					length = 1000;
				}
				fis.read(b,0,length);
				for(int i = 0;i<length;i++){
					sb.append((char)b[i]);
//					System.out.println(b[i]);
				}
				length = fis.available();
			}
			fis.close();
//			System.out.println(sb.toString());
			int m = 0;
			int n = 0;
			int count = 0;boolean f = false;
			while(n<sb.length()&&m<sb.length()){
				n=sb.indexOf("\r\n", m);
//				System.out.println(n);
				String s = null;
				if(n==-1){
					n=sb.length();
				}				
				s=sb.substring(m, n);
				File ff = new File(s);
				if(ff.isFile()==false){
					System.out.println(s+" file not exist");
				}else{System.out.println(s+" is ok");}
				m=n+2;
				count ++;
				if(count>1000){System.out.println("count break"); break;}
			}
		}catch (FileNotFoundException e){
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				fis.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
